<!DOCTYPE html>
<html class="x-admin-sm">
  <head>
    <meta charset="UTF-8">
    <title>新增品牌</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
      <!--百度ueditor-->
    <script src="__ADMIN__/plus/ueditor/ueditor.config.js"></script>
    <script src="__ADMIN__/plus/ueditor/ueditor.all.min.js"></script>

    <script type="text/javascript" src="__ADMIN__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
    <script type="text/javascript" src="__ADMIN__/js/cookie.js"></script>
  </head>
  <script type="text/javascript">
    layui.use('upload', function(){
      var $ = layui.jquery
      ,upload = layui.upload;
      //普通图片上传
      var uploadInst = upload.render({
          elem: '#uploads'
          , url: '{:url("Lunbo/upload")}'
          , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result){
                //如果有图片再点击上传就撤销原来的图片
                var img=$("#img").attr("src");
                var imgurl=$("#logo").val();
                if(img){
                    $.ajax({
                        type:"post",
                        dataType:"json",
                        data:{imgurl:imgurl},
                        url:"{:url('Lunbo/cancel')}",
                        success:function(data){
                        }
                    });
                }
                $('#img').attr('src', result); //图片链接(base64)
            });
          }
          , done: function (res) {
              //如果上传失败
              if (res.code == 0) {
                  return layer.msg(res.err);
              }
              //上传成功
              if(res.code == 1) {
                  $('#logo').attr('value',res.savename);
              }
          }
      });
  });
  </script>
  <body>
    <div class="x-body">
        <form class="layui-form">
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                轮播名称
              </label>
              <div class="layui-input-block">
                  <input type="text"  name="lb_name" required="" lay-verify="required"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                轮播图
              </label>
              <div class="layui-input-block">
                  <button type="button" style="width: 140px;" class="layui-btn layui-btn-sm layui-btn-normal" id="uploads"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                  <img class="layui-upload-img" id="img" src="" width="140px" style="margin-top: 5px;display: block;">
                  <input type="hidden" name="img_url" id="logo" value="" />
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  链接地址
              </label>
              <div class="layui-input-block">
                  <input type="text"  name="lb_url" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label"><span class="x-red">*</span>显示状态</label>
              <div class="layui-input-block">
                <input type="radio" name="status" value="0" lay-skin="primary" title="隐藏" >
                <input type="radio" name="status" value="1" lay-skin="primary" title="显示" checked="">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  确定新增
              </button>
          </div>
      </form>
    </div>
    <script>

        layui.use(['form','layer'], function(){
          $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;

          //监听提交
          form.on('submit(add)', function(data){
            $.ajax({
                type:'POST',
                dataType:'json',
                data:{data:data.field},
                url:"{:url('Lunbo/add')}",
                success:function(obj){
                  layer.alert(obj.msg, {icon: obj.icon},function(){
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                    // 可以对父窗口进行刷新 
                    x_admin_father_reload();
                  });
                }
            });
            return false;
          });
          
        });
    </script>
  </body>

</html>